<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Top 50 war points' );

$query = "SELECT name, score, ruler_id, experience, resigned, warrior_points " .
		"FROM ruler " .
		"ORDER BY warrior_points DESC, experience DESC, score DESC LIMIT 0, 50 ";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
?>
					<div id="blok">
						<?php transprint( 'War score is the sum of the amount of rulers with lower battle score each turn.' ); ?>
					</div>
					<br />
					<table id="twothird">
						<tr><th colspan="6"><?php transprint( 'Top 50 war points' ); ?></th></tr>
						<tr>
							<td><?php transprint( 'War rank' ); ?></td>
							<td><?php transprint( 'Name' ); ?></td>
							<td align="right"><?php transprint( 'War points' ); ?></td>
							<td align="right"><?php transprint( 'Battle score' ); ?></td>
							<td align="right"><?php transprint( 'Score' ); ?></td>
						</tr>
<?php
$i = 0;
while ( $i < $num ) {
    if( $i % 2 == 0 ) {
        print "<tr id=\"even\">";
    }
    else {
        print "<tr>";
    }
    if( mysql_result( $result, $i, "warrior_points" ) > 0 ) {
		$query = "SELECT count(*) FROM ruler WHERE warrior_points > " . mysql_result( $result, $i, "warrior_points" );
		$result2 = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$rank = number_format( $row2[ 'count(*)' ] + 1 );
    }
    else {
    	$rank = "-";
    }
    if( mysql_result( $result, $i, "resigned" ) == 1 ) {
    	$resigned = " (" . translate ( "resigned" ) . ")";
    }
    else {
    	$resigned = "";
    }
    
    print "<td align=\"right\">" . ( $rank ) . "</td>" .
    		"<td><a href=\"ruler.php?name=" .  mysql_result( $result, $i, "name" ) . "\">" . mysql_result( $result, $i, "name" ) . "</a>$resigned</td>" .
    		"<td align=\"right\">" . number_format( mysql_result( $result, $i, "warrior_points" ) ) . "</td>" .
    		"<td align=\"right\">" .  number_format( mysql_result( $result, $i, "experience" ) ) . "</td>" .
    		"<td align=\"right\">" .  number_format( mysql_result( $result, $i, "score" ) ) . "</td></tr>\r\n";
    $i ++;
}
?>	
				</table>
<?php
aos_footer();
?>